//
//  HYSeatListCell.m
//  Booking
//
//  Created by Duntech on 2018/4/23.
//  Copyright © 2018年 Duntech. All rights reserved.
//

#import "HYSeatListCell.h"
#import "HYSeatCellModel.h"

@interface HYSeatListCell ()

@property (nonatomic,strong) UILabel *availiableLabel;
@property (nonatomic,strong) UILabel *seatNoLabel;
@property (nonatomic,strong) UILabel *addressLabel;
@property (nonatomic,strong) UILabel *capacityLabel;
@property (nonatomic,strong) UIView *line;


@end

@implementation HYSeatListCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self setupSubviews];
        [self setupMasonryLayout];
    }
    return self;
}

- (void)setupSubviews{
    
    [self.contentView addSubview:self.availiableLabel];
    [self.contentView addSubview:self.seatNoLabel];
    [self.contentView addSubview:self.addressLabel];
    [self.contentView addSubview:self.line];
    [self.contentView addSubview:self.capacityLabel];
}

- (void)setupMasonryLayout{
    
    
    [_availiableLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.top.equalTo(self).offset(10 * WIDTH_MULTIPLE);
        make.height.mas_equalTo(20 * WIDTH_MULTIPLE);
    }];
    
    [_seatNoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.availiableLabel.mas_right).offset(15 * WIDTH_MULTIPLE);
        make.top.bottom.equalTo(self.availiableLabel);
        make.width.mas_equalTo(150);
    }];
    
    [_addressLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.availiableLabel);
        make.top.equalTo(self.availiableLabel.mas_bottom).offset(15 * WIDTH_MULTIPLE);
        make.height.mas_equalTo(20 * WIDTH_MULTIPLE);
        make.right.equalTo(self.capacityLabel.mas_left).offset(-20);
    }];
    
    [_capacityLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.addressLabel.mas_bottom).offset(18 * WIDTH_MULTIPLE);
        make.height.mas_equalTo(20 * WIDTH_MULTIPLE);
        make.right.equalTo(self).offset(-20);
    }];
    
    [_line mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.right.bottom.equalTo(self.contentView);
        make.height.mas_equalTo(0.5);
    }];
}

- (void)configWithModel:(id)model{
    
    HYSeatCellModel *seatModel = (HYSeatCellModel *)model;
    
    self.seatNoLabel.text = seatModel.name;
    self.addressLabel.text = [NSString stringWithFormat:@"%@ %@ %@",seatModel.cityName,seatModel.buildName,seatModel.floorName];
    
    _capacityLabel.text = [NSString stringWithFormat:@"%@：38",NSLocalizedString(@"capacity", nil)];
    _availiableLabel.text = [seatModel.status integerValue] == 1 ? NSLocalizedString(@"available", nil) :NSLocalizedString(@"unavailable", nil);
    _availiableLabel.backgroundColor = [seatModel.status integerValue] == 1 ? KAPP_WHITE_COLOR : KAPP_THEME_COLOR;
    _availiableLabel.backgroundColor = [seatModel.status integerValue] == 1 ?  KAPP_Available_COLOR : [UIColor lightGrayColor];
}

#pragma mark - lazyload
- (UILabel *)availiableLabel{
    
    if (!_availiableLabel) {
        _availiableLabel = [UILabel new];
        _availiableLabel.textAlignment = NSTextAlignmentCenter;
        _availiableLabel.font = KFitFont(13);
        _availiableLabel.textColor = KAPP_WHITE_COLOR;
        _availiableLabel.backgroundColor = KAPP_Available_COLOR;
        _availiableLabel.text = NSLocalizedString(@"available", nil);
        _availiableLabel.layerCornerRadius = 2;
    }
    return _availiableLabel;
}

- (UILabel *)seatNoLabel{
    
    if (!_seatNoLabel) {
        _seatNoLabel = [UILabel new];
        _seatNoLabel.textAlignment = NSTextAlignmentLeft;
        _seatNoLabel.font = KFitFont(15);
        _seatNoLabel.textColor = KAPP_BLACK_COLOR;
        _seatNoLabel.text = @"";
    }
    return _seatNoLabel;
}

- (UILabel *)addressLabel{
    
    if (!_addressLabel) {
        _addressLabel = [UILabel new];
        _addressLabel.textAlignment = NSTextAlignmentLeft;
        _addressLabel.font = KFitBoldFont(20);
        _addressLabel.textColor = KAPP_BLACK_COLOR;
        _addressLabel.text = @"上海 金桥大厦 10楼";
    }
    return _addressLabel;
}

- (UILabel *)capacityLabel{
    
    if (!_capacityLabel) {
        _capacityLabel = [UILabel new];
        _capacityLabel.textAlignment = NSTextAlignmentLeft;
        _capacityLabel.font = KFitFont(14);
        _capacityLabel.textColor = RGBColor(102, 102, 102);
        _capacityLabel.text = NSLocalizedString(@"capacity", nil);
        _capacityLabel.textAlignment = NSTextAlignmentRight;
    }
    return _capacityLabel;
}

- (UIView *)line{
    
    if (!_line) {
        _line = [UIView new];
        _line.backgroundColor = KAPP_SEPERATOR_COLOR;
    }
    return _line;
}

- (void)awakeFromNib {
    [super awakeFromNib];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
